package com.example.demo1.controller;


import com.example.demo1.model.User;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-01-07
 * Time: 13:02
 */
@RestController
@RequestMapping("/param")
public class ParamController {
    @RequestMapping("/print1")
    public String print1(String name) {
         return "name: " + name;
    }

    @RequestMapping("/print2")
    public String print2(String name, Integer age,String gender) {
        return "name: " + name +" " +  "age: " + age + " " + "gender: " + gender;
    }

    @RequestMapping("/print3")
    public String print3(User user) {
        return "user: " + user;
    }


    @RequestMapping("/print4")
    public String print4(@RequestParam("userName") String name) {
        return "name: " + name;
    }

    @RequestMapping("/print5")
    public String print5(@RequestParam(value = "userName",required = false)String name) {
        return "name: " + name;
    }

    @RequestMapping("/print6")
    public String print6(String[] name) {
        return "s = " + List.of(name);
    }

    @RequestMapping("/print7")
    public String print7(@RequestParam List<String> list) {
        return "list = " + list;
    }

    @RequestMapping("/print8")
    public String print8(@RequestBody User user) {
        return "user = " + user;
    }

    @RequestMapping("/print9/{article}/{name}")
    public String print9(@PathVariable("article") String articleId ,@PathVariable(value = "name") String name) {
        return "articleId: " + articleId +" " + "name: " + name;
    }

    @RequestMapping("/print10")
    public String print10(@RequestPart("fileName") MultipartFile file) {
        System.out.println(file.getOriginalFilename());
        return "fileName: " + file.getOriginalFilename();
    }
}
